package com.kiln.juxingqs.adapter

import androidx.recyclerview.widget.DiffUtil
import client.global.commlib.base.BasePagingAdapter
import client.global.commlib.base.PagingViewHoder
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.ZrAndSgRet
import com.kiln.juxingqs.databinding.LayoutZrandsgitemBinding

class ZrAndSgAdapter :
    BasePagingAdapter<ZrAndSgRet.Order>(object : DiffUtil.ItemCallback<ZrAndSgRet.Order>() {
        override fun areItemsTheSame(
            oldItem: ZrAndSgRet.Order,
            newItem: ZrAndSgRet.Order
        ): Boolean {
            return oldItem.order_id == newItem.order_id
        }

        override fun areContentsTheSame(
            oldItem: ZrAndSgRet.Order,
            newItem: ZrAndSgRet.Order
        ): Boolean {
            return oldItem == newItem
        }
    }) {

    var type = 0
    var cOrder: ((b: ZrAndSgRet.Order) -> Unit)? = null

    fun cancleOrder(b: ZrAndSgRet.Order) {
        cOrder?.invoke(
            b
        )
    }

    var qrOrder: ((b: ZrAndSgRet.Order) -> Unit)? = null

    fun querenOrder(b: ZrAndSgRet.Order) {
        qrOrder?.invoke(
            b
        )
    }

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutZrandsgitemBinding
        val bean = t as ZrAndSgRet.Order
        binding.bean = bean
        binding.type = "$type"
        binding.event = this
        val time = bean.create_time.substring(
            5,
            bean.create_time.length - 3
        )
        binding.time = time
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_zrandsgitem
    }
}